package com.ruoyi.web.controller.system;

import java.util.List;
import java.util.Arrays;

import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.vo.PStoreProductReplyVo;
import com.ruoyi.system.domain.bo.PStoreProductReplyBo;
import com.ruoyi.system.service.IPStoreProductReplyService;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.ApiOperation;

/**
 * 评论Controller
 *
 * @author ruoyi
 * @date 2022-08-01
 */
@Validated
@Api(value = "评论控制器", tags = {"评论管理"})
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/storeProductReply")
public class PStoreProductReplyController extends BaseController {

    private final IPStoreProductReplyService iPStoreProductReplyService;

    /**
     * 查询评论列表
     */
    @ApiOperation("查询评论列表")
    @SaCheckPermission("system:storeProductReply:list")
    @GetMapping("/list")
    public TableDataInfo<PStoreProductReplyVo> list(PStoreProductReplyBo bo, PageQuery pageQuery) {
        return iPStoreProductReplyService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出评论列表
     */
    @ApiOperation("导出评论列表")
    @SaCheckPermission("system:storeProductReply:export")
    @Log(title = "评论", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(PStoreProductReplyBo bo, HttpServletResponse response) {
        List<PStoreProductReplyVo> list = iPStoreProductReplyService.queryList(bo);
        ExcelUtil.exportExcel(list, "评论", PStoreProductReplyVo.class, response);
    }

    /**
     * 获取评论详细信息
     */
    @ApiOperation("获取评论详细信息")
    @SaCheckPermission("system:storeProductReply:query")
    @GetMapping("/{id}")
    public R<PStoreProductReplyVo> getInfo(@ApiParam("主键")
                                     @NotNull(message = "主键不能为空")
                                     @PathVariable("id") Long id) {
        return R.ok(iPStoreProductReplyService.queryById(id));
    }

    /**
     * 新增评论
     */
    @ApiOperation("新增评论")
    @SaCheckPermission("system:storeProductReply:add")
    @Log(title = "评论", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody PStoreProductReplyBo bo) {
        return toAjax(iPStoreProductReplyService.insertByBo(bo) ? 1 : 0);
    }

    /**
     * 修改评论
     */
    @ApiOperation("修改评论")
    @SaCheckPermission("system:storeProductReply:edit")
    @Log(title = "评论", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody PStoreProductReplyBo bo) {
        return toAjax(iPStoreProductReplyService.updateByBo(bo) ? 1 : 0);
    }

    /**
     * 删除评论
     */
    @ApiOperation("删除评论")
    @SaCheckPermission("system:storeProductReply:remove")
    @Log(title = "评论", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@ApiParam("主键串")
                                       @NotEmpty(message = "主键不能为空")
                                       @PathVariable Long[] ids) {
        return toAjax(iPStoreProductReplyService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }
}
